{include file="header.htm" /}
<body class="bodystyle" style="overflow-y: scroll; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-20">
    {include file="bar.htm" /}
    <div class="flexigrid flexigrid-xin">
        <div class="mDiv pt0">
            <div class="ftitle">
                <div class="fbutton">
                    <a href="{:weapp_url('Seckill/Seckill/add')}">
                        <div class="add">
                            <span><i class="layui-icon layui-icon-addition"></i>添加活动</span>
                        </div>
                    </a>
                </div>
            </div>
        </div>
        <div class="header-bar mb20">
            <div class="more">
                <div class="search">
                    <div class="content">
                        <form id="postForm" action="{:weapp_url('Seckill/Seckill/index')}" method="get" onsubmit="layer_loading('正在处理');" style="display: unset;">
                            {$searchform.hidden|default=''}
                            <div class="ey-form-item"><label class="users-form-item-label">活动名称：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="keywords" autocomplete="off" value="{$Request.param.keywords}" class="qsbox" style="width: 170px;" placeholder="活动名称...">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="ey-form-item"><label class="users-form-item-label">活动状态：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div>
                                                <select name="status">
                                                    <option value="">全部</option>
                                                    <option value="1" {eq name="$Request.param.status" value="1"} selected {/eq}>进行中</option>
                                                    <option value="2" {eq name="$Request.param.status" value="2"} selected {/eq}>未开始</option>
                                                    <option value="4" {eq name="$Request.param.status" value="3"} selected {/eq}>已停止</option>
                                                    <option value="3" {eq name="$Request.param.status" value="4"} selected {/eq}>手动停止</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="ey-form-item"><label class="users-form-item-label">活动时间：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" name="start_time" id="start_time" autocomplete="off" value="{$Request.param.start_time}" class="qsbox" placeholder="起始日期" lay-key="1">
                                            </div>
                                            &nbsp;至&nbsp;
                                            <div class="sDiv2">
                                                <input type="text" name="end_time" id="end_time" autocomplete="off" value="{$Request.param.end_time}" class="qsbox" placeholder="结束日期" lay-key="2">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item"><label class="users-form-item-label">活动商品：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="title" id="title" value="{$Request.param.title}" autocomplete="off" class="qsbox" style="width: 170px;" placeholder="关键词...">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <div class="ey-form-item" style="margin-left: 20px;">
                            <div class="users-form-item-content">
                                <span class="bt-xin" onclick="SearchQuery();">查询</span>
                                <span class="bt-xin-no" onclick="SearchQuery('reset');">重置</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="flexigrid">
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th abbr="article_title" axis="col3">
                            <div class="text-l10">活动名称</div>
                        </th>
                        <th abbr="" axis="col4" class="w280">
                            <div class="tc">活动时间</div>
                        </th>
                        <th abbr="" axis="col6" class="w120">
                            <div class="tc">成交订单</div>
                        </th>
                        <th abbr="" axis="col6" class="w120">
                            <div class="tc">成交金额</div>
                        </th>
                        <th abbr="" axis="col6" class="w120">
                            <div class="tc">活动状态</div>
                        </th>
                        <th abbr="" axis="col6" class="w120">
                            <div class="tc">参加活动</div>
                        </th>
                        <th abbr="" axis="col5" class="w250">
                            <div class="tc">操作</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <div class="no_row">
                                    <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                </div>
                            </td>
                        </tr>
                    {else/}
                        {volist name="list" id="vo"}
                        <tr>
                            <td style="width: 100%" class="">
                                <div class="text-l10">
                                    {$vo.activity_title}
                                </div>
                            </td>
                            <td>
                                <div class="w280 tc" style="">
                                    {$vo.start_time|MyDate='Y-m-d H:i:s',###} ~ {$vo.end_time|MyDate='Y-m-d H:i:s',###}
                                </div>
                            </td>
                            <td class="">
                                <div class="w120 tc">
                                    {$vo.total_order}
                                </div>
                            </td>
                            <td class="">
                                <div class="w120 tc">
                                    <span class="red">￥{$vo.total_money}</span>
                                </div>
                            </td>
                            
                            <td class="">
                                <div class="w120 tc">
                                    {if condition="1 == $vo.status"}
                                    <span class="green">进行中</span>
                                    {elseif condition="2 == $vo.status"}
                                    <span class="green">未开始</span>
                                    {elseif condition="3 == $vo.status"}
                                    <span class="red" title="停止时间:{$vo.stop_time|MyDate='Y-m-d H:i:s',###}">手动停止</span>
                                    {elseif condition="4 == $vo.status"}
                                    <span class="red">已停止</span>
                                    {/if}
                                </div>
                            </td>
                            <td class="">
                                <div class="w120 tc">
                                    {if condition="$vo['in_progress'] eq 0"}
                                    <span class="no" onclick="changeInProgress(this);" data-id="{$vo.id}" data-value="{$vo.in_progress}" ><i class="fa fa-ban"></i>选择</span>
                                    {else /}
                                    <span class="yes" onclick="changeInProgress(this);" data-id="{$vo.id}" data-value="{$vo.in_progress}" ><i class="fa fa-check-circle"></i>已选</span>
                                    {/if}
                                </div>
                            </td>
                            <td>
                                <div class="w250 tc">
                                    <!-- 进行中 -->
                                    <a href="javascript:void(0);" data-href="{:weapp_url('Seckill/Seckill/edit',['id'=>$vo['id'],'fetch'=>'view'])}" onclick="openFullframe(this, '查看活动', '100%', '100%');" class="btn">查看</a>
                                    {neq name="$vo.status" value="2"}
                                    <a class="btn" href="javascript:void(0);" data-href="{:weapp_url('Seckill/Seckill/active_sale_data', ['id'=>$vo['id']])}" onclick="openFullframe(this, '活动数据');">数据</a>
                                    {else}
                                    <a href="" class="btn grey">数据</a>
                                    {/neq}
                                    {if condition='$vo.status == 1 || $vo.status == 2'}
                                    <a href="{:weapp_url('Seckill/Seckill/edit',array('id'=>$vo['id']))}" class="btn">编辑</a>
                                    {else}
                                    <a href="" class="btn grey">编辑</a>
                                    {/if}
                                    <!-- 点击复制时，复制当前数据并跳转到发布活动 -->
                                    <a href="{:weapp_url('Seckill/Seckill/copy_add', ['id'=>$vo['id']])}" class="btn">复制</a>
                                    {eq name="$vo.status" value="1"}
                                    <a href="javascript:void(0);" data-url="{:weapp_url('Seckill/Seckill/stop_activity')}" data-id="{$vo.id}" onclick="stopActivity(this);" data-title="{$vo.activity_title}" class="btn">停止</a>
                                    {else}
                                    <a href="" class="btn grey">停止</a>
                                    {/eq}

                                    {if condition='$vo.status == 3 || $vo.status == 4'}
                                    <a class="btn" href="javascript:void(0)" data-url="{:weapp_url('Seckill/Seckill/del')}" data-id="{$vo.id}" onclick="delfun(this);">删除</a>
                                    {else}
                                    <a class="btn grey"  href="javascript:void(0)">删除</a>
                                    {/if}
                                </div>
                            </td>
                        </tr>
                        {/volist}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        {include file="page.htm" /}
    </div>
</div>
<script>
    layui.use(['form', 'laydate'], function(){
        var form = layui.form,
            laydate = layui.laydate;

        laydate.render({
            elem: '#start_time',
            type: 'datetime'
        });
        laydate.render({
            elem: '#end_time',
            type: 'datetime'
        });

        form.render();
    });

    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });
    });

    // 查询
    function SearchQuery(isReset) {
        if (isReset && 'reset' == isReset) {
            window.location.href = "{:weapp_url('Seckill/Seckill/index')}";
        } else {
            $('#postForm').submit();
        }
    }

    function stopActivity(obj) {
        var title = $(obj).data('title');
        layer.confirm('确认停止活动-'+title+'？', {
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            // shade: layer_shade,
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确定','取消'] ,//按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function () {
            layer_loading('正在处理');
            $.ajax({
                url: $(obj).data('url'),
                type: 'post',
                dataType: 'json',
                data:{id:$(obj).data('id'),_ajax:1},
                success: function(res){
                    layer.closeAll();
                    if (1 == res.code) {
                        layer.msg(res.msg, {time: 1000},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {time: 1500, icon: 5});
                    }
                },
                error : function(e) {
                    layer.closeAll();
                    layer.alert(e.responseText, {icon: 5});
                }
            });
        }, function (index) {
            layer.closeAll(index);
        });
    }

    function changeInProgress(obj)
    {
        var value = $(obj).data('value');
        if (value == 0) {
            var msg = "开启此秒杀活动,将会关闭其他秒杀活动。";
            layer.confirm(msg, {
                area: ['480px', '230px'],
                move: false,
                title: '提示',
                btnAlign:'r',
                closeBtn: 3,
                btn: ['确定','取消'] ,//按钮
                success: function () {
                    $(".layui-layer-content").css('text-align', 'left');
                }
            }, function(){
                changeWeappTableVal(1,obj);
            }, function(index){
                layer.close(index);
            });
        }else{
            changeWeappTableVal(0,obj);
        }
    }

    function changeWeappTableVal(value,obj)
    {
        if($(obj).hasClass('no')) // 图片点击是否操作
        {
            var text = "<i class='fa fa-check-circle'></i>已选";
            if ($(obj).attr('data-yestext')) {
                text = $(obj).attr('data-yestext');
            }
        }else if($(obj).hasClass('yes')){ // 图片点击是否操作
            var text = "<i class='fa fa-ban'></i>选择";
            if ($(obj).attr('data-notext')) {
                text = $(obj).attr('data-notext');
            }
        }
        if (parseInt($(obj).attr('data-value')) === 0) {
            $(obj).attr('data-value', 1);
        } else if (parseInt($(obj).attr('data-value')) === 1) {
            $(obj).attr('data-value', 0);
        }

        var id_value = $(obj).data('id');
        $.ajax({
            type: 'POST',
            url: "{:weapp_url('Seckill/Seckill/set_in_progress')}",
            data: {id:id_value,value:value},
            dataType: 'json',
            success: function(res){
                if (res.code == 1) {
                    if ($(obj).hasClass('no')) {
                        $(obj).removeClass('no').addClass('yes');
                        $(obj).html(text);
                    }else if($(obj).hasClass('yes')) {
                        $(obj).removeClass('yes').addClass('no');
                        $(obj).html(text);
                    }
                    layer.msg(res.msg,{icon: 1, time: 1000}, function(){
                        window.location.reload();
                    });
                } else {
                    layer.alert(res.msg);
                }
            }
        });
    }

</script>
{include file="footer.htm" /}
